-- 获取指定路径按钮的所有属性
-- 路径: Players.matye0829.PlayerGui.Gift_Notification.Frame.Gift_Notification.Holder.Frame.Accept

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

local LocalPlayer = Players.LocalPlayer

local function log(msg)
	print("[ButtonProps] " .. msg)
	local ok = pcall(function()
		appendfile("button_properties_log.txt", "[ButtonProps] " .. msg .. "\n")
	end)
	if not ok then
		pcall(function()
			writefile("button_properties_log.txt", "[ButtonProps] " .. msg .. "\n")
		end)
	end
end

-- 根据路径获取按钮
local function getButtonByPath()
	local pg = LocalPlayer:FindFirstChild("PlayerGui")
	if not pg then 
		log("❌ 找不到 PlayerGui")
		return nil 
	end
	
	local giftNotification = pg:FindFirstChild("Gift_Notification")
	if not giftNotification then 
		log("❌ 找不到 Gift_Notification")
		return nil 
	end
	
	local frame1 = giftNotification:FindFirstChild("Frame")
	if not frame1 then 
		log("❌ 找不到 Gift_Notification.Frame")
		return nil 
	end
	
	local giftNotification2 = frame1:FindFirstChild("Gift_Notification")
	if not giftNotification2 then 
		log("❌ 找不到 Gift_Notification.Frame.Gift_Notification")
		return nil 
	end
	
	local holder = giftNotification2:FindFirstChild("Holder")
	if not holder then 
		log("❌ 找不到 Gift_Notification.Frame.Gift_Notification.Holder")
		return nil 
	end
	
	local frame2 = holder:FindFirstChild("Frame")
	if not frame2 then 
		log("❌ 找不到 Gift_Notification.Frame.Gift_Notification.Holder.Frame")
		return nil 
	end
	
	local accept = frame2:FindFirstChild("Accept")
	if not accept then 
		log("❌ 找不到 Gift_Notification.Frame.Gift_Notification.Holder.Frame.Accept")
		return nil 
	end
	accept.Visible = false

		
	local decline = frame2:FindFirstChild("Decline")
	if not decline then 
		log("❌ 找不到 Gift_Notification.Frame.Gift_Notification.Holder.Frame.decline")
		return nil 
	end
	decline.Visible = false
	log("✅ 成功找到 Accept 按钮")
	return accept
end

-- 获取按钮的所有属性
local function getButtonProperties(btn)
	if not btn then return end
	
	log("=== Accept 按钮属性分析 ===")
	log("路径: " .. btn:GetFullName())
	
	-- 基本信息
	log("=== 基本信息 ===")
	log("名称: " .. btn.Name)
	log("类型: " .. btn.ClassName)
	log("可见: " .. tostring(btn.Visible))
	log("激活: " .. tostring(btn.Active))
	log("父级: " .. (btn.Parent and btn.Parent.Name or "nil"))
	
	-- 位置和大小
	log("=== 位置和大小 ===")
	pcall(function()
		log("Size: " .. tostring(btn.Size))
		log("Position: " .. tostring(btn.Position))
		log("AbsoluteSize: " .. tostring(btn.AbsoluteSize))
		log("AbsolutePosition: " .. tostring(btn.AbsolutePosition))
		log("ZIndex: " .. tostring(btn.ZIndex))
		log("LayoutOrder: " .. tostring(btn.LayoutOrder))
	end)
	
	-- 外观属性
	log("=== 外观属性 ===")
	pcall(function()
		log("BackgroundColor3: " .. tostring(btn.BackgroundColor3))
		log("BackgroundTransparency: " .. tostring(btn.BackgroundTransparency))
		log("BorderColor3: " .. tostring(btn.BorderColor3))
		log("BorderSizePixel: " .. tostring(btn.BorderSizePixel))
		log("ClipsDescendants: " .. tostring(btn.ClipsDescendants))
	end)
	
	-- 图片属性（ImageButton特有）
	log("=== 图片属性 ===")
	pcall(function()
		log("Image: " .. tostring(btn.Image))
		log("ImageColor3: " .. tostring(btn.ImageColor3))
		log("ImageTransparency: " .. tostring(btn.ImageTransparency))
		log("ScaleType: " .. tostring(btn.ScaleType))
		log("SliceCenter: " .. tostring(btn.SliceCenter))
		log("SliceScale: " .. tostring(btn.SliceScale))
		log("TileSize: " .. tostring(btn.TileSize))
	end)
	
	-- 事件属性
	log("=== 事件属性 ===")
	pcall(function()
		log("Activated: " .. tostring(btn.Activated))
		if btn.Activated then
			log("Activated 类型: " .. tostring(typeof(btn.Activated)))
			log("Activated 连接数: " .. tostring(#btn.Activated:GetConnections()))
		end
		log("MouseEnter: " .. tostring(btn.MouseEnter))
		log("MouseLeave: " .. tostring(btn.MouseLeave))
		log("MouseButton1Down: " .. tostring(btn.MouseButton1Down))
		log("MouseButton1Up: " .. tostring(btn.MouseButton1Up))
		log("MouseButton1Click: " .. tostring(btn.MouseButton1Click))
	end)
	
	-- 输入属性
	log("=== 输入属性 ===")
	pcall(function()
		log("AutoButtonColor: " .. tostring(btn.AutoButtonColor))
		log("HoverImage: " .. tostring(btn.HoverImage))
		log("PressedImage: " .. tostring(btn.PressedImage))
		log("Selected: " .. tostring(btn.Selected))
		log("SelectionImageObject: " .. tostring(btn.SelectionImageObject))
	end)
	
	-- 布局属性
	log("=== 布局属性 ===")
	pcall(function()
		log("AnchorPoint: " .. tostring(btn.AnchorPoint))
		log("Rotation: " .. tostring(btn.Rotation))
		log("SizeConstraint: " .. tostring(btn.SizeConstraint))
		log("AutomaticSize: " .. tostring(btn.AutomaticSize))
	end)
	
	-- 渲染属性
	log("=== 渲染属性 ===")
	pcall(function()
		log("LocalizationTable: " .. tostring(btn.LocalizationTable))
		log("RootLocalizationTable: " .. tostring(btn.RootLocalizationTable))
		log("SelectionBehaviorDown: " .. tostring(btn.SelectionBehaviorDown))
		log("SelectionBehaviorLeft: " .. tostring(btn.SelectionBehaviorLeft))
		log("SelectionBehaviorRight: " .. tostring(btn.SelectionBehaviorRight))
		log("SelectionBehaviorUp: " .. tostring(btn.SelectionBehaviorUp))
		log("SelectionGroup: " .. tostring(btn.SelectionGroup))
		log("SelectionOrder: " .. tostring(btn.SelectionOrder))
	end)
	
	-- 子级元素
	log("=== 子级元素 ===")
	for i, child in ipairs(btn:GetChildren()) do
		log("子级 " .. i .. ": " .. child.Name .. " (" .. child.ClassName .. ")")
		if child:IsA("GuiObject") then
			log("  可见: " .. tostring(child.Visible))
			log("  激活: " .. tostring(child.Active))
			log("  ZIndex: " .. tostring(child.ZIndex))
		end
	end
	
	-- 父级链
	log("=== 父级链 ===")
	local parent = btn.Parent
	local depth = 0
	while parent and depth < 10 do
		log("父级 " .. depth .. ": " .. parent.Name .. " (" .. parent.ClassName .. ")")
		log("  可见: " .. tostring(parent.Visible))
		log("  激活: " .. tostring(parent.Active))
		log("  ZIndex: " .. tostring(parent.ZIndex))
		parent = parent.Parent
		depth = depth + 1
	end
end

-- 测试按钮点击
local function testButtonClick(btn)
	if not btn then return false end
	
	log("=== 测试按钮点击 ===")
	
	local methods = {
		{"直接Activated", function()
			if btn.Activated then
				btn.Activated:Fire()
				return true
			end
		end},
		{"Fire(Activated)", function()
			btn:Fire("Activated")
			return true
		end},
		{"Fire(MouseButton1Click)", function()
			btn:Fire("MouseButton1Click")
			return true
		end},
		{"模拟点击", function()
			local pos = btn.AbsolutePosition
			local size = btn.AbsoluteSize
			local centerX = pos.X + size.X / 2
			local centerY = pos.Y + size.Y / 2
			
			UserInputService:SendMouseButtonEvent(centerX, centerY, 0, true, game)
			wait(0.05)
			UserInputService:SendMouseButtonEvent(centerX, centerY, 0, false, game)
			return true
		end}
	}
	
	local successCount = 0
	for i, method in ipairs(methods) do
		local success = pcall(function()
			return method[2]()
		end)
		if success then
			log("方法 " .. i .. " (" .. method[1] .. "): ✅ 成功")
			successCount = successCount + 1
		else
			log("方法 " .. i .. " (" .. method[1] .. "): ❌ 失败")
		end
		wait(0.1)
	end
	
	log("成功方法数: " .. successCount .. "/" .. #methods)
	return successCount > 0
end

-- 主函数
local function analyzeAcceptButton()
	log("开始分析 Accept 按钮...")
	
	local btn = getButtonByPath()
	if btn then
		getButtonProperties(btn)
		testButtonClick(btn)
	else
		log("❌ 无法找到 Accept 按钮")
	end
end

-- 快捷键
UserInputService.InputBegan:Connect(function(input, gp)
	if gp then return end
	
	if input.KeyCode == Enum.KeyCode.A then
		analyzeAcceptButton()
	end
end)

-- 启动
log("按钮属性分析器已启动")
log("按 A 键分析 Accept 按钮属性")

-- 自动分析
spawn(function()
	while true do
		local btn = getButtonByPath()
		if btn then
			log("检测到 Accept 按钮，开始分析...")
			getButtonProperties(btn)
			testButtonClick(btn)
			break
		end
		wait(1)
	end
end)
